﻿using System;
using System.Data;
using System.Text;
using System.Data.OleDb;
using Maticsoft.DBUtility;//请先添加引用
namespace TuKu.DAL
{
    /// <summary>
    /// 数据访问类urlcate。
    /// </summary>
    public class urlcate
    {
        public urlcate()
        { }
        #region  成员方法


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(TuKu.Model.urlcate model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into urlcate(");
            strSql.Append("catename,enname,sortid,addtime)");
            strSql.Append(" values (");
            strSql.Append("@catename,@enname,@sortid,@addtime)");
            OleDbParameter[] parameters = {
					new OleDbParameter("@id", OleDbType.Integer,4),
					new OleDbParameter("@catename", OleDbType.VarChar,50),
					new OleDbParameter("@enname", OleDbType.VarChar,50),
					new OleDbParameter("@sortid", OleDbType.Integer,4),
					new OleDbParameter("@addtime", OleDbType.Date)};
            parameters[0].Value = model.catename;
            parameters[1].Value = model.enname;
            parameters[2].Value = model.sortid;
            parameters[3].Value = model.addtime;

            DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(TuKu.Model.urlcate model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update urlcate set ");
            strSql.Append("catename=@catename,");
            strSql.Append("enname=@enname,");
            strSql.Append("sortid=@sortid,");
            strSql.Append("addtime=@addtime");
            strSql.Append(" where id=@id ");
            OleDbParameter[] parameters = {
					new OleDbParameter("@id", OleDbType.Integer,4),
					new OleDbParameter("@catename", OleDbType.VarChar,50),
					new OleDbParameter("@enname", OleDbType.VarChar,50),
					new OleDbParameter("@sortid", OleDbType.Integer,4),
					new OleDbParameter("@addtime", OleDbType.Date)};
            parameters[0].Value = model.id;
            parameters[1].Value = model.catename;
            parameters[2].Value = model.enname;
            parameters[3].Value = model.sortid;
            parameters[4].Value = model.addtime;

            DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from urlcate ");
            strSql.Append(" where id=@id ");
            OleDbParameter[] parameters = {
					
					new OleDbParameter("@id", OleDbType.Integer,4)};

            parameters[0].Value = id;

            DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public TuKu.Model.urlcate GetModel(int id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,catename,enname,sortid,addtime from urlcate ");
            strSql.Append(" where id=@id ");
            OleDbParameter[] parameters = {
				
					new OleDbParameter("@id", OleDbType.Integer,4)};
            parameters[0].Value = id;
            TuKu.Model.urlcate model = new TuKu.Model.urlcate();
            DataSet ds = DbHelperOleDb.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                model.catename = ds.Tables[0].Rows[0]["catename"].ToString();
                model.enname = ds.Tables[0].Rows[0]["enname"].ToString();
                if (ds.Tables[0].Rows[0]["sortid"].ToString() != "")
                {
                    model.sortid = int.Parse(ds.Tables[0].Rows[0]["sortid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["addtime"].ToString() != "")
                {
                    model.addtime = DateTime.Parse(ds.Tables[0].Rows[0]["addtime"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,catename,enname,sortid,addtime ");
            strSql.Append(" FROM urlcate ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOleDb.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OleDbParameter[] parameters = {
                    new OleDbParameter("@tblName", OleDbType.VarChar, 255),
                    new OleDbParameter("@fldName", OleDbType.VarChar, 255),
                    new OleDbParameter("@PageSize", OleDbType.Integer),
                    new OleDbParameter("@PageIndex", OleDbType.Integer),
                    new OleDbParameter("@IsReCount", OleDbType.Bit),
                    new OleDbParameter("@OrderType", OleDbType.Bit),
                    new OleDbParameter("@strWhere", OleDbType.VarChar,1000),
                    };
            parameters[0].Value = "urlcate";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperOleDb.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  成员方法
    }
}

